Welcome to Css!

第六章:css必学基础

6.01 元素宽高特点1

1、块级元素

1)可以设置宽高;

2)不能和其他元素呆在一行

3)当没有设置宽高时,宽度和父级宽度一样,高度由元素内容的高度决定(可以理解成body元素下的元素没有设置宽度时,body默认的完度会在浏览器两端留空)

4)当设置有宽高时,元素的宽高就是设置的值

未设置浏览器两端留空:

设置之后:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>css</title>

<style type="text/css">

*{padding:0;margin:0}

<!--此行设置是将body默认两端留空的宽设置为0-->

</style>

</head>

<body>

<div style="background:blue;width:200px;height:20px"> 我要好好学习<br>我要好好学习</div>

<br>

<br>

<div > 我要好好学习<br>我要好好学习</div>

</body>

</html>

返回: